#!/bin/sh
python3 extract_spectra.py                        # extract spectra from data cubes
python3 extract_template_spectrum.py              # extract and create a template spectrum from the methanol data
python3 extract_template_H218O.py                 # extract and create a template spectrum from the LIME model
python3 plotTemplates.py                          # plot template spectra with each other
python3 write_text_spectral_templates.py          # write out the spectral templates as text files

casa -c make_casa_images_from_fits.py             # import the provided FITS images into CASA image format
casa -c moments-water_5_to_7_kms.py                      # make moment map for HDO/H218O moment maps between 5.05 to 7.05 km/s

python3 extract_flux_moment0.py                   # get HDO/H218O line fluxes from 5 to 7 km/s range

#run in CASA 6.2+ (works up to at least CASA 6.5.2) and takes awhile
# requires ~ at least 64 GB of RAM to create these masks, esp. on the CH3OH cube
casa -c keplerian_mask_steps_same_params.py 
# or use pre-made masks supplied in tar.gz file
# tar xvf keplerian-masks.tar.gz

python3 make_moment_maps.py                       # make moment 0 maps using Keplerian masks and bettermoments
casa -c moments-CH3OH.py                          # make simple moment map for CH3OH data

python3 extract_line_flux_keplerian_mask.py       # extract flux of water lines from Keplerian masks
python3 plot_channel_maps.py                      # plot channel maps of HDO and H218O
python3 make_radial_profiles.py                   # make radial profiles using Keplerian masks
python3 make_nice_radial_profiles.py              # make a nice plot of radial intensity profiles


# casa -c regrid_LSRK_stack_CH3OH.py               # makes a stacked line cube of the isolated methanol lines, requires MS files

python3 stack_cubes.py                            # remove velocity profile from line cubes 'line stacking'
python3 stack_lime_template.py                    # stack the LIME template
python3 extract_template_spectrum_stacked.py      # extract template spectrum from the CH3OH stacked data cube
python3 extract_template_spectrum_lime_stacked.py # extract the lime template spectrum from the stacked LIME model
python3 write_text_spectral_templates_stacked.py  # write out the stacked spectral templates as text files
python3 plotTemplates_stacked.py                  # plot stacked template spectra with each other
python3 plot_stacked_spectra.py                   # plot stacked spectra with line IDs for HDO and H218O


# the following will run after just first three steps to provide disk averaged measurements but will stop 
# where radial profile creation starts
python3 make_HDO_Trot_profile_final.py H218O      # make HDO/H2O calculations from disk-averaged spectrum
                                                  # and makes radial profile calculations
                                                  # command line arguments enable more options for calculating
                                                  # the HDO/H2O ratio from different measurements

# python3 make_HDO_Trot_profile_final.py stacked-methanol   # e.g., print results from fitting line stacked data

# make Figures requires aplpy and cmocean for the cmo.ice color map
python3 disk-images-1panel-single-mom0.py V883_Ori_SB_C17O-224.711GHz_robust_2.0.image_M0.fits V883Ori.C17O.1.3mm.pdf \
84.5754282 -7.04055 -15e-4 0.045  1.25 0.1 400 'C$^{17}$O (J=2-1)' 302.0 n 11.0e-6 n n linear \
V883_Ori_SB_continuum_235GHz_robust_0.5.image.tt0.fits 4.0 2.0 6.1e-5 y color gist_heat 'd)' 'white' 0.0 0.0 'black' 'white' \
2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o_M0.fits y

python3 disk-images-1panel-single-mom0.py V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.image_M0.fits V883Ori.H2CO.1.3mm.pdf \
84.5754282 -7.04055 -15e-4 0.060  2.0 0.1 400 'H$_2$CO (J=3$_{1,2}$-2$_{1,1})$' 302.0 n 11.0e-6 n n sqrt \
V883_Ori_SB_continuum_235GHz_robust_0.5.image.tt0.fits 4.0 2.0 6.1e-5 y color gist_heat 'b)' 'white' 0.0 0.0 'black' 'white' \
2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y  V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co_M0.fits y

python disk-images-1panel-single-mom0.py V883_Ori_SB_HDO-225.535GHz_robust_2.0.image_M0.fits V883Ori.HDO.225.1.3mm.pdf \
84.5754282 -7.04055 0.0 0.062 1.25 0.1 400 'HDO 225.896 GHz' 302.0 n 11.0e-6 n n linear \
V883_Ori_SB_continuum_235GHz_robust_0.5.image.tt0.fits 4.0 2.0 6.1e-5 y color cmo.ice 'a)' 'white' 0.0 0.0 'black' 'white' \
2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-hdo_M0.fits y

python disk-images-1panel-single-mom0.py V883_Ori_SB_HDO-241.558GHz_robust_2.0.image_M0.fits V883Ori.HDO.241.1.3mm.pdf \
84.5754282 -7.04055 0.0 0.082  1.25 0.1 400 'HDO 241.561 GHz' 302.0 n 11.0e-6 n n linear \
V883_Ori_SB_continuum_235GHz_robust_0.5.image.tt0.fits 4.0 2.0 6.1e-5 y color cmo.ice 'a)' 'white' 0.0 0.0 'black' 'white' \
2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-hdo_M0.fits y

python disk-images-1panel-single-mom0.py V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.image_M0.fits V883Ori.CH3OH.241.1.3mm.pdf \
84.5754282 -7.04055 -15e-4 0.45  1.25 0.1 400 'CH$_3$OH 241.85 GHz' 302.0 n 11.0e-6 n n linear \
V883_Ori_SB_continuum_235GHz_robust_0.5.image.tt0.fits 4.0 2.0 6.1e-5 y color gist_heat 'c)' 'white' 0.0 0.0 'black' 'white' \
2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-h218o_M0.fits n

python disk-images-1panel-single-mom0.py V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image_M0.fits V883Ori.H218O.203.1.5mm.pdf \
84.5754282 -7.04055 0.0 0.020  1.25 0.1 400 'H$_2$$^{18}$O 203.407 GHz' 302.0 n 11.0e-6 n n linear \
V883_Ori_SB_continuum_203GHz_robust_0.5.image.tt0.fits 4.0 2.0 7.1e-5 y color cmo.ice 'b)' 'white' 0.0 0.0 'black' 'white' \
2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-h218o_M0.fits y


python disk-images-1panel-double-mom0.py V883_Ori_SB_HDO-225.535GHz_robust_2.0.image_M0_5.05_7.05kms.fits V883Ori.HDO.225_5.05_7.05kms.1.3mm.pdf \
84.5754282 -7.04055 0.0 0.05  1.25 0.1 400 'HDO 225 GHz (5 -7 km/s)' 302.0 n 11.0e-6 n n linear \
V883_Ori_SB_continuum_235GHz_robust_0.5.image.tt0.fits 4.0 100000 6.1e-5 y  V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image_M0_5.05_7.05kms.fits 3.0 2.0 1.58e-3 y \
color cmo.ice 'c)' 'white' 0.0 0.0 'black' 'white' 2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y


python disk-images-1panel-double-mom0.py V883_Ori_SB_HDO-241.558GHz_robust_2.0.image_M0_5.05_7.05kms.fits V883Ori.HDO.241_5.05_7.05kms.1.3mm.pdf \
84.5754282 -7.04055 0.0 0.05  1.25 0.1 400 'HDO 241 GHz (5 - 7 km/s)' 302.0 n 11.0e-6 n n linear \
V883_Ori_SB_continuum_235GHz_robust_0.5.image.tt0.fits 4.0 100000 6.1e-5 y V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image_M0_5.05_7.05kms.fits 3.0 2.0 1.58e-3 y \
 color cmo.ice 'b)' 'white' 0.0 0.0 'black' 'white'  2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y 


python disk-images-1panel-double-mom0.py V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image_M0_5.05_7.05kms.fits V883Ori.H218O_5.05_7.05kms.203.1.5mm.pdf \
84.5754282 -7.04055 0.0 0.01  1.25 0.1 400 'H$_2$$^{18}$O 203 GHz (5 - 7 km/s)' 302.0 n 11.0e-6 n n linear \
V883_Ori_SB_continuum_203GHz_robust_0.5.image.tt0.fits 4.0 100000.0 7.1e-5 y V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image_M0_5.05_7.05kms.fits 3.0 2.0 1.58e-3 y \
color cmo.ice 'd)' 'white' 0.0 0.0 'black' 'white' 2.038170687026E-05 1.529375712077E-05 -7.726993560791E+01 y 


# perform raster combinations of the image figures
montage -density 300 -compress JPEG -quality 90 -mode concatenate -tile 2x2  V883Ori.HDO.225.1.3mm.pdf V883Ori.H218O.203.1.5mm.pdf V883Ori.CH3OH.241.1.3mm.pdf V883Ori.C17O.1.3mm.pdf f2.pdf
montage -density 300 -compress JPEG -quality 90 -mode concatenate -tile 2x1 HDO_H218O_Column_Density_Profile_K_Trot_profile.pdf HDO_H2O_Column_Density_Profile.pdf f3.pdf
montage -density 300 -compress JPEG -quality 90 -mode concatenate -tile 1x2 HDO_225.pdf HDO_241.pdf edf1.pdf
montage -density 300 -compress JPEG -quality 90 -mode concatenate -tile 2x2 V883Ori.HDO.241.1.3mm.pdf V883Ori.HDO.241_5.05_7.05kms.1.3mm.pdf V883Ori.HDO.225_5.05_7.05kms.1.3mm.pdf V883Ori.H218O_5.05_7.05kms.203.1.5mm.pdf edf3.pdf
montage -density 300 -compress JPEG -quality 90 -mode concatenate -tile 2x3 HDO_225_best_fit_combined.pdf HDO_225_stack_line_ids.pdf HDO_241_best_fit_combined.pdf HDO_241_stack_line_ids.pdf H218O_203_best_fit_combined.pdf H218O_203_stack_line_ids.pdf edf4.pdf 

python3 make_dh_figure.py




